# 4.设计一个学生类Student，包含学号、姓名和成绩属性，以及计算平均分的方法。
#     参考答案：
# class Student:
#     def __init__(self, student_id, name, scores):
#         self.student_id = student_id
#         self.name = name
#         self.scores = scores  # scores是一个成绩列表
#     def calculate_average(self):
#         if len(self.scores) == 0:
#             return 0
#         return sum(self.scores) / len(self.scores)
#     def display_info(self):
#         avg_score = self.calculate_average()
#         print(f'学号：{self.student_id}，姓名：{self.name}，平均分：{avg_score:.2f}')
# # 测试代码
# scores = [85, 90, 78, 92, 88]
# student1 = Student('2023001', '张三', scores)
# student1.display_info()


# 6.设计一个简单的银行账户类，包含存款、取款和查询余额的方法。
#     参考答案：
class BankAccount:
    def __init__(self, account_holder, initial_balance=0):
        self.account_holder = account_holder
        self.balance = initial_balance
    def deposit(self, amount):
        if amount > 0:
            self.balance += amount
            print(f"存款成功！当前余额：{self.balance}")
        else:
            print("存款金额必须大于0")
    def withdraw(self, amount):
        if amount > 0:
            if amount <= self.balance:
                self.balance -= amount
                print(f"取款成功！当前余额：{self.balance}")
            else:
                print("余额不足")
        else:
            print("取款金额必须大于0")
    def check_balance(self):
        print(f"账户持有人：{self.account_holder}")
        print(f"当前余额：{self.balance}")
        return self.balance
# 测试代码
account = BankAccount("张三", 1000)
account.check_balance()
account.deposit(500)
account.withdraw(200)
account.withdraw(2000)  # 测试余额不足情况